package cn.edu.scau.cmi.linjinyong.adapter;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import cn.edu.scau.cmi.linjinyong.adapter.adaptee.SortUtil;
import cn.edu.scau.cmi.linjinyong.adapter.pojo.Student;
import cn.edu.scau.cmi.linjinyong.adapter.target.SortStudent;

public class StudentSortUtil01 extends SortUtil implements SortStudent{

	@Override
	public List<Student> sortStudent(List<Student> students) {
		//获取学生学号并排序
		List<Integer> list = students.stream().map(s->s.getId()).collect(Collectors.toList());
		list = super.sortInt(list);
		
		//根据学号顺序给学生List排序
		List<Student> sortedStudents = new ArrayList<Student>(students.size());
		for(Integer id: list) {
			for(Student s: students) {
				if(s.getId().equals(id)) {
					sortedStudents.add(s);
					break;
				}
			}
		}
		return sortedStudents;
	}

}
